package cn.bonoon.kernel.web.components;

import cn.bonoon.handler.impl.StandardAutoManager;
import cn.bonoon.kernel.descriptors.UIPropertyAccessor;
import cn.bonoon.kernel.web.annotations.AutoDataLoader;
import cn.bonoon.kernel.web.annotations.components.AsComboBox;
import cn.bonoon.kernel.web.handlers.loader.ComboAutoLoaderHandler;
import cn.bonoon.kernel.web.handlers.loader.ComboBoxAutoLoaderHandler;
import cn.bonoon.kernel.web.html.UIPropertyBuilder;
import cn.bonoon.kernel.web.html.form.ComponentPropertyParser;

public class ComboBoxComponent extends AbstractComboComponent {
	private final AsComboBox asComboBox;
	public ComboBoxComponent(ComponentPropertyParser property, UIPropertyAccessor accessor, AsComboBox asComboBox) {
		super("buppancombo", asComboBox.value(), property, accessor, asComboBox.reload());
		this.asComboBox = asComboBox;
	}
	
	@Override
	protected void initInputAttribute(StringBuilder html, StringBuilder settings, UIPropertyBuilder builder) {
		super.initInputAttribute(html, settings, builder);
//		html.append(", valueField:'").append(asComboBox.valueField()).append("', textField:'").append(asComboBox.textField()).append("'\"");
	}
	
	@Override
	protected ComboAutoLoaderHandler builderHandler(StandardAutoManager builderInitializer, AutoDataLoader autoLoader) throws Throwable{
		return new ComboBoxAutoLoaderHandler(builderInitializer, autoLoader, accessor.getField());
	}
	
	@Override
	protected void initComponentAttribute(StringBuilder script, UIPropertyBuilder builder) {
		super.initComponentAttribute(script, builder);
		script.append(", valueField:'").append(asComboBox.valueField()).append("', textField:'").append(asComboBox.textField()).append("'");
	}
}
